package comxin.demo1.jdbcdemo;

import comxin.demo1.Utils.JdbcUtils;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class jdbcdemo_02 {
    public static void main(String[] args) {
        Connection conn=null;
        Statement sta=null;
        try {
            conn= JdbcUtils.getConnection();
            sta=conn.createStatement();
            // 这里就是对数据库表进行 update，delete，insert语句
            String sql1="update stu_information set stu_id=1,stu_name='张三',gender='男' where stu_id=3";
            String sql2="delete from stu_information where stu_id=20";
            String sql3="insert into stu_information (stu_id,stu_name,gender) values(2,'李四','男')";
            //这里返回几行受影响
            int i = sta.executeUpdate(sql3);
            System.out.println(i==1?"执行成功":"执行失败");
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JdbcUtils.close(conn,sta);
        }
    }
}
